package com.test.dao.impl;

import com.test.dao.IHouseMeterCurrentDao;
import com.test.model.HouseMeterCurrentData;
import org.hibernate.Hibernate;
import org.hibernate.Query;
import org.hibernate.transform.Transformers;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * Created by ZZF on 2017/6/29.
 */
@Repository
public class HouseMeterCurrentDaoImpl extends BaseDaoImpl<HouseMeterCurrentData> implements IHouseMeterCurrentDao {


    @Override
    public List<HouseMeterCurrentData> findStationBranch(int StationBranchId) {

        String Sql="SELECT {c.*} FROM rcc_d_housemetercurrentdata c INNER JOIN rcc_e_housemeter d on d.uniqueId" +
                "=c.houseMeterId WHERE stationBranchId= "+StationBranchId;

        Query query= getSession().createSQLQuery(Sql).addEntity("c",HouseMeterCurrentData.class);

        return query.list();
    }

    @Override
    public Map<String, String> findMaxTmperature(int stationBrandId) {

        String Sql = "SELECT MAX(c.supplyTemperature) AS supplyTemperature,MAX(c.returnTemperature) AS returnTemperature " +
                "FROM rcc_d_housemetercurrentdata c INNER JOIN rcc_e_housemeter d on d.uniqueId=c.houseMeterId " +
                "WHERE stationBranchId="+stationBrandId;

        Query query = getSession().createSQLQuery(Sql).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);

        Map<String, String> data = (Map<String, String>) query.uniqueResult();


        return data;
    }


}
